import 'package:flutter/material.dart';
import 'package:nim_core/nim_core.dart';

import 'chat_thumb_view.dart';
import 'picture_viewer.dart';


class ChatMessageImageItem extends StatefulWidget {
   NIMMessage message;

   ChatMessageImageItem({Key key, this.message})
      : super(key: key);

  @override
  State<StatefulWidget> createState() => ChatMessageImageState();
}

class ChatMessageImageState extends State<ChatMessageImageItem> {
   bool _isReceive;

  @override
  void initState() {
    super.initState();
    _isReceive =
        widget.message.messageDirection == NIMMessageDirection.received;
  }

  @override
  Widget build(BuildContext context) {
    return ChatThumbView(
        message: widget.message,
        radius: BorderRadius.only(
            // topLeft: Radius.circular(_isReceive ? 0 : 12),
            // topRight: Radius.circular(_isReceive ? 12 : 0),
            topLeft: const Radius.circular(12),
            topRight: const Radius.circular(12),
            bottomLeft: const Radius.circular(12),
            bottomRight: const Radius.circular(12)),
        onTap: () {
          // var messagesList = context
          //     .read<ChatViewModel>()
          //     .messageList
          //     .where((element) =>
          //         element.nimMessage.messageAttachment is NIMImageAttachment)
          //     .map((e) => e.nimMessage)
          //     .toList();
          Navigator.push(
              context,
              MaterialPageRoute(
                  builder: (context) => PictureViewer(
                      // messages: messagesList,
                      messages: [widget.message],
                      // showIndex: messagesList.indexOf(widget.message)
                      showIndex: [widget.message].indexOf(widget.message)
                  )));
        });
  }
}
